﻿using Persistencia;
using System;
using System.Collections.Generic;
using System.Data.Linq.SqlClient;
using System.Linq;
using System.Text;

namespace Dlls
{
  public  class RequisicaoDLL
    {
          Context context;

        public RequisicaoDLL()
        {
            context = new Context();
        }
        public IEnumerable<Requisicoe> List()
        {
            return (from o in context.Requisicao select o).ToList();
        }

        public void Insert(Requisicoe requisicao)
        {
            context.Requisicao.InsertOnSubmit(requisicao);
            context.SubmitChanges();
        }

        public void Update(int codigo, Requisicoe requisicao)
        {
            Requisicoe requi = context.Requisicao.SingleOrDefault(o => o.Codigo == codigo);
            requi.DataAtendimento = requisicao.DataAtendimento;
            requi.Situacao = requisicao.Situacao;
            requi.DataCriacao = requisicao.DataCriacao;
            context.SubmitChanges();
        }
        public void Delete(Requisicoe requisicao)
        {
            context.Requisicao.DeleteOnSubmit(requisicao);
            context.SubmitChanges();
        }
        public IEnumerable<Requisicoe> ListPorCodigo(int codigo)
        {
            return (from o in context.Requisicao where o.Codigo==codigo select o).ToList();
        }
       
        public Requisicoe getRequisicao(int codigo)
        {
            return context.Requisicao.SingleOrDefault(e => e.Codigo == codigo);
        }

    }
    
}
